package com.szqhyxj.youxiangju.biz.partnerHome.equipment.currentRecord;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;

import com.szqhyxj.youxiangju.BasePromptFragment;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.partnerHome.equipment.bean.Record;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * XiaoPanYu
 * on 2018/11/22
 */
public class CurrentRecordFragment extends BasePromptFragment implements CurrentRecordContract.View{
    private static final String TYPE = "type";

    @BindView(R.id.current_scene)
    ExpandableListView currentScene;
    Unbinder unbinder;

    private CurrentRecordAdapter adapter;
    private List<String> timeList;
    private List<Record> recordList;

    public static CurrentRecordFragment newInstance(int type){
        Bundle args = new Bundle();
        args.putInt(TYPE,type);
        CurrentRecordFragment fragment = new CurrentRecordFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void start(){
        CurrentRecordPresenter presenter = new CurrentRecordPresenter(this);
        int type = getArguments().getInt(TYPE);
        presenter.init(type);
        timeList = new ArrayList<>();
        recordList = new ArrayList<>();
        adapter = new CurrentRecordAdapter(timeList,recordList);
        currentScene.setAdapter(adapter);
        initView();
    }

    private void initView(){

    }

    @Override
    protected int getLayoutId(){
        return R.layout.fragment_current_record;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView(){
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void showCurrentRecord(List<Record> recordList,List<String> timeList){
        this.recordList.addAll(recordList);
        this.timeList.addAll(timeList);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void navDetailed(){

    }
}
